﻿using System;

namespace MessagePack.Formatters
{
	// Token: 0x02000028 RID: 40
	public class NullableFormatter<T> : IMessagePackFormatter<T?> where T : struct
	{
		// Token: 0x06000092 RID: 146 RVA: 0x0000384C File Offset: 0x00001C4C
		public int Serialize(ref byte[] bytes, int offset, T? value, IFormatterResolver formatterResolver)
		{
			if (value == null)
			{
				return MessagePackBinary.WriteNil(ref bytes, offset);
			}
			return formatterResolver.GetFormatterWithVerify<T>().Serialize(ref bytes, offset, value.Value, formatterResolver);
		}

		// Token: 0x06000093 RID: 147 RVA: 0x0000387C File Offset: 0x00001C7C
		public T? Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
		{
			if (MessagePackBinary.IsNil(bytes, offset))
			{
				readSize = 1;
				return null;
			}
			return new T?(formatterResolver.GetFormatterWithVerify<T>().Deserialize(bytes, offset, formatterResolver, out readSize));
		}
	}
}
